<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单名称" prop="orderName">
        <el-input
          v-model="queryParams.orderName"
          placeholder="请输入订单名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户编号" prop="customerId">
        <el-input
          v-model="queryParams.customerId"
          placeholder="请输入客户编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="蔬菜类型编号" prop="cropTypeId">
        <el-input
          v-model="queryParams.cropTypeId"
          placeholder="请输入蔬菜类型编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="苗类型嫁接苗 | 实生苗" prop="seedlingType">
        <el-select v-model="queryParams.seedlingType" placeholder="请选择苗类型嫁接苗 | 实生苗" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="砧木品种 实生苗不需要填写砧木" prop="stockBreed">
        <el-input
          v-model="queryParams.stockBreed"
          placeholder="请输入砧木品种 实生苗不需要填写砧木"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接穗品种" prop="scionBreed">
        <el-input
          v-model="queryParams.scionBreed"
          placeholder="请输入接穗品种"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="接单日期" prop="receiveorderDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.receiveorderDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择接单日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预计出圃日期" prop="deliveryDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.deliveryDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择预计出圃日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单数量" prop="orderAmount">
        <el-input
          v-model="queryParams.orderAmount"
          placeholder="请输入订单数量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同单价" prop="contractPrice">
        <el-input
          v-model="queryParams.contractPrice"
          placeholder="请输入合同单价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型 代育加工 | 全部委托" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型 代育加工 | 全部委托" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态 接单 | 实施中 | 完成" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态 接单 | 实施中 | 完成" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:order:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:order:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['order:order:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['order:order:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="orderId" />
      <el-table-column label="订单名称" align="center" prop="orderName" />
      <el-table-column label="客户名称" align="center" prop="customer" />
      <el-table-column label="蔬菜类型" align="center" prop="cropType" />
      <el-table-column label="苗类型" align="center" prop="seedlingType" />
      <el-table-column label="砧木品种" align="center" prop="stockBreed" />
      <el-table-column label="接穗品种" align="center" prop="scionBreed" />
      <el-table-column
        label="接单日期"
        align="center"
        prop="receiveorderDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.receiveorderDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="预计出圃日期"
        align="center"
        prop="deliveryDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单数量" align="center" prop="orderAmount" />
      <el-table-column label="合同单价" align="center" prop="contractPrice" />
      <el-table-column label="订单要求" align="center" prop="requirement" />
      <el-table-column label="订单类型" align="center" prop="orderType" />
      <el-table-column label="订单状态" align="center" prop="status" />
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['order:order:edit']"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['order:order:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="订单分配" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleAllocationAdd(scope.row)"
            >订单分配</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="订单实施" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleFulfillmentAdd(scope.row)"
            >实施安排</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单编号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单编号 类似20210621001这种格式编号" />
        </el-form-item>
        <el-form-item label="订单名称" prop="orderName">
          <el-input v-model="form.orderName" placeholder="请输入订单名称" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerId">
          <!-- <el-input v-model="form.customerId" placeholder="请输入客户编号" /> -->
          <el-select
            v-model="form.customerId"
            placeholder="请选择客户名称"
            size="small"
          >
            <el-option
              v-for="(customer, index) in customerName"
              :key="index"
              :label="customer.customerName"
              :value="customer.customerId"
            >
            </el-option>
          </el-select>
        </el-form-item>
         <el-form-item label="蔬菜类型" prop="cropTypeId">
          <el-select
            v-model="form.cropTypeId"
            placeholder="请选择蔬菜类型"
            size="small"
          >
            <el-option
              v-for="(crop, index) in cropType"
              :key="index"
              :label="crop.cropTypeName"
              :value="crop.cropTypeId"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="苗类型" prop="seedlingType">
          <el-select v-model="form.seedlingType" placeholder="请选择苗类型">
            <el-option label="嫁接苗" value="嫁接苗" />
            <el-option label="实生苗" value="实生苗" />
          </el-select>
        </el-form-item>
        <el-form-item label="砧木品种" prop="stockBreed">
          <el-input v-model="form.stockBreed" placeholder="请输入砧木品种" />
        </el-form-item>
        <el-form-item label="接穗品种" prop="scionBreed">
          <el-input v-model="form.scionBreed" placeholder="请输入接穗品种" />
        </el-form-item>
        <el-form-item label="接单日期" prop="receiveorderDate">
          <el-date-picker
            clearable
            size="small"
            v-model="form.receiveorderDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择接单日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预计出圃日期" prop="deliveryDate" label-width="107px">
          <el-date-picker
            clearable
            size="small"
            v-model="form.deliveryDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择预计出圃日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单数量" prop="orderAmount">
          <el-input v-model.number="form.orderAmount" placeholder="请输入订单数量" />
        </el-form-item>
        <el-form-item label="合同单价" prop="contractPrice">
          <el-input v-model.number="form.contractPrice" placeholder="请输入合同单价" />
        </el-form-item>
        <el-form-item label="订单要求" prop="requirement">
          <el-input
            v-model="form.requirement"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="form.orderType" placeholder="请选择订单类型">
            <el-option label="代育加工" value="代育加工" />
            <el-option label="全部委托" value="全部委托" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-radio-group v-model="form.status">
            <el-radio label="接单">接单</el-radio>
            <el-radio label="实施中">实施中</el-radio>
            <el-radio label="完成">完成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input
            v-model="form.note"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改订单分配对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openAllocation"
      width="500px"
      append-to-body
    >
      <el-form
        ref="allocationform"
        :model="allocationform"
        :rules="allocationrules"
        label-width="80px"
      >
        <el-form-item label="片区名称" prop="areaId" :required="true">
          <el-select
            v-model="allocationform.areaId"
            placeholder="请选择片区名称"
            size="small"
          >
            <el-option
              v-for="(area,index) in areaName"
              :key="index"
              :value="area.areaId"
              :label="area.areaName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大棚名称" prop="greenhouseId" :required="true">
          <el-select
            v-model="allocationform.greenhouseId"
            placeholder="请选择大棚名称"
            size="small"
          >
            <el-option
              v-for="(greenhouse,index) in greenhouseName"
              :key="index"
              :label="greenhouse.greenhouseName"
              :value="greenhouse.greenhouseId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单编号" prop="orderId" :required="true">
          <el-input v-model="allocationform.orderId" readonly />
        </el-form-item>
        <el-form-item label="蔬菜类型" prop="cropTypeId" :required="true">
          <el-select
            v-model="allocationform.cropTypeId"
            placeholder="请选择蔬菜类型"
            size="small"
          >
            <el-option
              v-for="(crop, index) in cropType"
              :key="index"
              :label="crop.cropTypeName"
              :value="crop.cropTypeId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="苗类型" prop="seedlingType" :required="true">
          <el-select
            v-model="allocationform.seedlingType"
            placeholder="请选择苗类型"
          >
            <el-option label="嫁接苗" value="嫁接苗" />
            <el-option label="实生苗" value="实生苗" />
          </el-select>
        </el-form-item>
        <el-form-item label="砧木品种" prop="stockBreed">
          <el-input
            v-model="allocationform.stockBreed"
            placeholder="请输入砧木品种"
          />
        </el-form-item>
        <el-form-item label="接穗品种" prop="scionBreed">
          <el-input
            v-model.number="allocationform.scionBreed"
            placeholder="请输入接穗品种"
          />
        </el-form-item>
        <el-form-item label="计划数量" prop="amount" :required="true">
          <el-input
            v-model.number="allocationform.amount"
            placeholder="请输入计划数量"
          />
        </el-form-item>
        <el-form-item label="所占面积" prop="acreage" :required="true">
          <el-input
            v-model.number="allocationform.acreage"
            placeholder="请输入所占面积"
          />
        </el-form-item>
        <el-form-item label="单位" prop="unit" :required="true">
          <el-input v-model="allocationform.unit" placeholder="请输入单位" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAllocationForm"
          >确 定</el-button
        >
        <el-button @click="cancelAllocation">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改订单任务执行对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openFulfillment"
      width="500px"
      append-to-body
    >
      <el-form
        ref="fulfillmentform"
        :model="fulfillmentform"
        :rules="fulfillmentrules"
        label-width="80px"
      >
        <el-form-item label="订单编号" prop="orderId" :required="true">
          <el-input v-model="fulfillmentform.orderId" readonly />
        </el-form-item>
        <el-form-item label="操作名称" prop="operationId" :required="true">
          <el-select
            v-model="fulfillmentform.operationId"
            placeholder="请选择操作类型"
            size="small"
          >
            <el-option
              v-for="(operation, index) in operationName"
              :key="index"
              :label="operation.operationName"
              :value="operation.operationId"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="beginDate" :required="true">
          <el-date-picker
            clearable
            size="small"
            v-model="fulfillmentform.beginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endDate" :required="true">
          <el-date-picker
            clearable
            size="small"
            v-model="fulfillmentform.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="说明" prop="note">
          <el-input
            v-model="fulfillmentform.note"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFulfillmentForm"
          >确 定</el-button
        >
        <el-button @click="cancelFulfillment">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
  exportOrder,
} from "@/api/order/order";
import { addAllocation } from "@/api/order/allocation";
import { addFulfillment } from "@/api/order/fulfillment";
import { listArea } from "@/api/order/area";
import { listGreenhouse } from "@/api/order/greenhouse";
import { listType } from "@/api/applyParchaseUse/seed/type"
import { listOperation } from "@/api/order/operation"
import { listCustomer } from "@/api/order/customer"

export default {
  name: "Order",
  components: {},
  data() {
    return {
      customerName: [],
      operationName:[],
      areaName: [],
      greenhouseName: [],
      cropType: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示订单分配弹出
      openAllocation: false,
      // 是否显示订单实施弹出
      openFulfillment: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderName: null,
        customerId: null,
        cropTypeId: null,
        seedlingType: null,
        stockBreed: null,
        scionBreed: null,
        receiveorderDate: null,
        deliveryDate: null,
        orderAmount: null,
        contractPrice: null,
        requirement: null,
        orderType: null,
        status: null,
        note: null,
      },
      // 表单参数
      form: {},
      allocationform: {},
      fulfillmentform: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "订单编号不能为空", trigger: "biur" },
        ],
        orderName: [
          { required: true, message: "订单名称不能为空", trigger: "blur" },
        ],
        customerId: [
          { required: true, message: "客户编号不能为空", trigger: "blur" },
        ],
        cropTypeId: [
          { required: true, message: "蔬菜类型不能为空", trigger: "blur" },
        ],
        seedlingType: [
          {
            required: true,
            message: "苗类型嫁接苗 | 实生苗不能为空",
            trigger: "change",
          },
        ],
        receiveorderDate: [
          { required: true, message: "接单日期不能为空", trigger: "blur" },
        ],
        deliveryDate: [
          { required: true, message: "预计出圃日期不能为空", trigger: "blur" },
        ],
        orderAmount: [
          { required: true, message: "订单数量不能为空", trigger: "blur" },
          { type:'number',message:'订单数量必须为数字'}
        ],
        contractPrice: [
          { required: true, message: "合同单价不能为空", trigger: "blur" },
          { type:'number',message:'合同单价必须为数字'}
        ],
        orderType: [
          {
            required: true,
            message: "订单类型 代育加工 | 全部委托不能为空",
            trigger: "change",
          },
        ],
        status: [
          {
            required: true,
            message: "订单状态 接单 | 实施中 | 完成不能为空",
            trigger: "blur",
          },
        ],
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" },
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" },
        ],
        updateBy: [
          { required: true, message: "更新者不能为空", trigger: "blur" },
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" },
        ],
      },
      // 订单分配表单校验
      allocationrules: {
        areaId: [
          { required: true, message: "片区编号 外码不能为空", trigger: "blur" },
        ],
        greenhouseId: [
          { required: true, message: "大棚编号 外码不能为空", trigger: "blur" },
        ],
        orderId: [
          { required: true, message: "订单编号 外码不能为空", trigger: "blur" },
        ],
        cropTypeId: [
          {
            required: true,
            message: "蔬菜类型编号 外码不能为空",
            trigger: "blur",
          },
        ],
        seedlingType: [
          {
            required: true,
            message: "苗类型 嫁接苗|实生苗不能为空",
            trigger: "change",
          },
        ],
        amount: [
          { required: true, message: "计划数量不能为空", trigger: "blur" },
          { type:'number',message:'计划数量必须为数字'}
        ],
        acreage: [
          { required: true, message: "所占面积不能为空", trigger: "blur" },
          { type:'number',message:'所占面积必须为数字'}
        ],
        unit: [{ required: true, message: "单位不能为空", trigger: "blur" }],
        // createBy: [
        //   { required: true, message: "创建者不能为空", trigger: "blur" }
        // ],
        // createTime: [
        //   { required: true, message: "创建时间不能为空", trigger: "blur" }
        // ],
        // updateBy: [
        //   { required: true, message: "更新者不能为空", trigger: "blur" }
        // ],
      },
      // 订单实施表单校验
      fulfillmentrules: {
        orderId: [
          { required: true, message: "订单编号不能为空", trigger: "blur" },
        ],
        operationId: [
          { required: true, message: "操作名称不能为空", trigger: "blur" },
        ],
        beginDate: [
          { required: true, message: "开始时间不能为空", trigger: "blur" },
        ],
        endDate: [
          { required: true, message: "结束时间不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getAreaList();
    this.getList();
    this.getGreenhouseList();
    this.getCropList()
    this.getOperationList()
    this.getCustomerList();
    console.log(this.cropType)
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      // this.getAreaList();
      listOrder(this.queryParams).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
        // console.log(this.orderList);
      });
    },
    // 获取客户列表
    getCustomerList() {
      listCustomer().then((res) => {
        let data = res.rows
        // console.log(res.rows);
        data.forEach((customer) => {
          this.customerName.push({customerId:customer.customerId,customerName:customer.companyName})
        })
      })
    },
    // 获取操作类型
    getOperationList() {
      listOperation().then((res) => {
        // console.log(res.rows);
        let data = res.rows
        data.forEach((operation) => {
          this.operationName.push({operationId:operation.operationId,operationName:operation.operationName})
        })
      })
    },
    // 获取片区信息
    getAreaList() {
      listArea().then((res) => {
        console.log(res.rows);
        let data = res.rows;
        data.forEach((area) => {
          this.areaName.push({areaId:area.areaId,areaName:area.areaName});
        });
      });
    },
    // 获取大棚信息
    getGreenhouseList() {
      listGreenhouse().then((res) => {
        // console.log(res.rows);
        let datas = res.rows;
        datas.forEach((greenhouse) => {
          this.greenhouseName.push({greenhouseName:greenhouse.greenhouseName,greenhouseId:greenhouse.greenhouseId});
        });
      });
    },
    // 获取蔬菜类型信息
    getCropList() {
      listType().then((res) => {
        // console.log(res.rows);
        let dating = res.rows
        dating.forEach((crop) => {
          // console.log(crop);
          this.cropType.push({cropTypeName:crop.cropType,cropTypeId:crop.cropTypeId})
        })
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 订单分配取消按钮
    cancelAllocation() {
      this.openAllocation = false;
      this.resetAllocation();
    },
    // 订单实施取消按钮
    cancelFulfillment() {
      this.openFulfillment = false;
      this.resetFulfillment();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        orderName: null,
        customerId: null,
        cropTypeId: null,
        seedlingType: null,
        stockBreed: null,
        scionBreed: null,
        receiveorderDate: null,
        deliveryDate: null,
        orderAmount: null,
        contractPrice: null,
        requirement: null,
        orderType: null,
        status: "0",
        note: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    // 订单分配表单重置
    resetAllocation() {
      this.allocationform = {
        orderAllocationId: null,
        areaId: null,
        greenhouseId: null,
        orderId: null,
        cropTypeId: null,
        seedlingType: null,
        stockBreed: null,
        scionBreed: null,
        amount: null,
        acreage: null,
        unit: null,
        // createBy: null,
        // createTime: null,
        // updateBy: null,
        // updateTime: null
      };
      // this.resetAllocationForm("allocationform");
    },
    // 订单实施表单重置
    resetFulfillment() {
      this.fulfillmentform = {
        orderFulfillmentId: null,
        orderId: null,
        operationId: null,
        beginDate: null,
        endDate: null,
        note: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 订单分配重置按钮操作 */
    resetAllocatiionQuery() {
      this.resetAllocationForm("queryForm");
      this.handleQuery();
    },
    /** 重置按钮操作 */
    resetFulfillmentQuery() {
      this.resetFulfillmentForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   console.log(row)
    //   this.reset();
    //   const orderId = row.orderId || this.ids
    //   getOrder(orderId).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改订单";
    //   });
    // },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          // if (this.form.orderId != null) {
          //   updateOrder(this.form).then(response => {
          //     this.msgSuccess("修改成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // } else {
          addOrder(this.form).then((response) => {
            this.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$confirm(
        '是否确认删除订单编号为"' + orderIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delOrder(orderIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有订单数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportOrder(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    /** 订单分配按钮操作 */
    handleAllocationAdd(row) {
      // console.log(row);
      const orderIds = row.orderId;
      this.allocationform.orderId = orderIds;
      this.reset();
      this.openAllocation = true;
      this.title = "添加订单分配";
      // console.log(this.allocationform);
    },
    /** 提交订单分配按钮 */
    submitAllocationForm() {
      this.$refs["allocationform"].validate((valid) => {
        if (valid) {
          addAllocation(this.allocationform).then((response) => {
            this.msgSuccess("新增成功");
            this.openAllocation = false;
            // console.log(response);
            this.$router.push("/order/allocation");
          });
        }
      });
    },

    //订单实施按钮操作
    handleFulfillmentAdd(row) {
      const orderIds = row.orderId;
      this.fulfillmentform.orderId = orderIds;
      this.reset();
      this.openFulfillment = true;
      this.title = "添加订单实施";
    },
    /** 提交订单实施按钮 */
    submitFulfillmentForm() {
      this.$refs["fulfillmentform"].validate((valid) => {
        if (valid) {
          addFulfillment(this.fulfillmentform).then((response) => {
            this.msgSuccess("新增成功");
            this.openFulfillment = false;
            this.$router.push("/order/fulfillment");
          });
        }
      });
    },
  },
};
</script>
